package com.begye.smartloan.apptest.ext

import java.text.DecimalFormat

fun String.toNumberEncrypt(): String {

    if (this.length >= 6) {
        val start = this.substring(0, 3)
        val end = this.substring(this.length - 3)
        return "$start *** $end"
    }
    return this
}

fun String.toThousandUnitFormat(): String {
    return try {
        // 000000000000 - 000,000,000,000
        val number = this.toDouble()
        val formatter = DecimalFormat("#,###.##")
        formatter.format(number)
    } catch (e: Exception) {
        this
    }
}

fun String.toPercentUnitFormat(): String {
    return try {
        // 0.00098 - 0.098%
        val number = this.toDouble()
        val formatter = DecimalFormat("#.##%")
        formatter.format(number)
    } catch (e: Exception) {
        this
    }
}

fun String?.isUrl(): Boolean{
    if(this.isNullOrEmpty()) return false
    return this.startsWith("http://") || this.startsWith("https://")
}